import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.staticfiles import StaticFiles

from children.baoban import baoban_router
from children.caiwu import caiwu_router
from children.fuwu import fuwu_router
from children.jianpiao import jianpiao_router
from children.shoupiao import shoupiao_router
from children.zongkong import zongkong_router
from children.user import user_router
from admin import admin_router

app = FastAPI()

app.include_router(user_router,prefix='/user',tags=['用户模块'])
app.include_router(admin_router,prefix='/admin',tags=['管理员模块'])

app.include_router(baoban_router, prefix='/baoban',tags=["报班接口"])
app.include_router(caiwu_router, prefix='/caiwu',tags=["财务接口"])
app.include_router(fuwu_router, prefix='/fuwu',tags=["服务接口"])
app.include_router(jianpiao_router, prefix='/jianpiao',tags=["检票接口"])
app.include_router(shoupiao_router, prefix='/shoupiao',tags=["售票接口"])
app.include_router(zongkong_router, prefix='/zongkong',tags=["总控接口"])

#跨域设置
#允许的域名
origins = ["*"]

#使用add_middleware允许跨域
app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

#挂载静态文件
app.mount(path='/icons',app = StaticFiles(directory='hdc-python-service\static\icons'),name='icons')

@app.get('/main')
def main ():
  return{"hello":"world"}

# 代码内运行uvicorn
if __name__=='__main__':
  uvicorn.run(app="main:app",host='127.0.0.1',port=8000,reload=True)